// AgentProxy.h

#ifndef __AGENT_PROXY_H
#define __AGENT_PROXY_H



#include "Common/Archive/OpenArchive.h"

#include <vector>
#include <deque>
#include <memory>

namespace Common
{
namespace Agent
{

struct CProxyFile
{
  UINT32 Index;
  CString Name;
  CProxyFile() {}
  CProxyFile(const CProxyFile & obj) :
	  Index(obj.Index),
	  Name(obj.Name)
  {
  }
  CProxyFile& operator= (const CProxyFile & obj)
  {
	  Index = obj.Index;
	  Name = obj.Name;
	  return *this;
  }
};

struct CProxyFolder: public CProxyFile
{
	//TODO: change to use share_ptr
  CProxyFolder *Parent;
  std::vector<std::shared_ptr<CProxyFolder> > Folders;
  std::deque<CProxyFile> Files;
  bool IsLeaf;

  bool CrcIsDefined;
  UINT64 Size;
  UINT64 PackSize;
  UINT32 Crc;
  UINT32 NumSubFolders;
  UINT32 NumSubFiles;

  CProxyFolder(): Parent(NULL) {};
  int FindDirSubItemIndex(const CString &name, int &insertPos) const;
  int FindDirSubItemIndex(const CString &name) const;
  std::shared_ptr<CProxyFolder> AddDirSubItem(UINT32 index, bool leaf, const CString &name);
  void AddFileSubItem(UINT32 index, const CString &name);
  void Clear();

  void GetPathParts(CStringVector &pathParts) const;
  CString GetFullPathPrefix() const;
  CString GetItemName(UINT32 index) const;
  void AddRealIndices(std::vector<UINT32> &realIndices) const;
  void GetRealIndices(const UINT32 *indices, UINT32 numItems, std::vector<UINT32> &realIndices) const;
  void CalculateSizes(IInArchive *archive);
};

struct CProxyArchive
{
	std::shared_ptr<CProxyFolder> RootFolder;
  bool ThereIsPathProp;
  CProxyArchive() 
  {
	  RootFolder = std::make_shared<CProxyFolder>();
  }

  HRESULT Load(const Common::Archive::CArc * const pArc, IProgress *progress);
};

}}

#endif
